home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
amusemen
/
nolan-1.1
/
nolan.tar
/
screen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-25
|
4KB
|
170 lines
/*****************************************************************************
NAME
screen.c --- screen-handling primitives for the quiz program
*****************************************************************************/
/*LINTLIBRARY*/
#include <stdlib.h>
#ifdef NCURSES
#include <ncurses.h>
#else
#include <curses.h>
#endif /* NCURSES */
#ifdef CURSES
#include <string.h>
#include <stdarg.h>
#endif /* CURSES */
#ifndef A_UNDERLINE /* BSD curses */
#define cbreak crmode
#define saveterm savetty
#define resetterm resetty
#define nocbreak nocrmode
#define strchr index
#endif /* !A_UNDERLINE */
void initscreen(void)
/* initialize screen routines and clear screen */
{
#ifdef CURSES
(void) initscr();
(void) saveterm();
(void) nonl();
(void) cbreak();
(void) noecho();
#ifdef A_COLOR
start_color();
init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
#endif /* A_COLOR */
(void) clear();
#endif /* CURSES */
}
void endscreen(void)
/* de-initialize screen routines */
{
#ifdef CURSES
(void)refresh();
(void)resetterm();
(void)echo();
(void)endwin();
#endif /* CURSES */
}
void clearscreen(void)
/* return the x index to start a string at to center it on screen */
{
#ifdef CURSES
clear();
#endif /* CURSES */
}
void sputs(char *prompt)
/* present a next-page prompt and wait for any key */
{
#ifdef CURSES
addstr(prompt);
#endif /* CURSES */
}
void scprintf(char *format, int arg1)
/* present a next-page prompt and wait for any key */
{
#ifdef CURSES
printw(format, arg1);
#endif /* CURSES */
}
void sputc(char ch)
/* put character to screen, advance cursor */
{
#ifdef CURSES
addch(ch);
#endif /* CURSES */
}
char sgetch(void)
/* get a character, no echo */
{
#ifdef CURSES
return(getch());
#endif /* CURSES */
}
void screenloc(int *py, int *px)
/* get the current cursor location */
{
#ifdef CURSES
getyx(stdscr, *py, *px);
#endif /* CURSES */
}
void movecursor(int y, int x)
/* move the cursor to a given position */
{
#ifdef CURSES
move(y, x);
#endif /* CURSES */
}
#ifdef CURSES
/*
* Highlight-handling code
*/
static char *attrnames = "xgrcwmbyXGRCWMBY";
static int colorpairs[] =
{
COLOR_PAIR(COLOR_BLACK),
COLOR_PAIR(COLOR_GREEN),
COLOR_PAIR(COLOR_RED),
COLOR_PAIR(COLOR_CYAN),
COLOR_PAIR(COLOR_WHITE),
COLOR_PAIR(COLOR_MAGENTA),
COLOR_PAIR(COLOR_BLUE),
COLOR_PAIR(COLOR_YELLOW),
COLOR_PAIR(COLOR_BLACK) | A_BOLD,
COLOR_PAIR(COLOR_GREEN) | A_BOLD,
COLOR_PAIR(COLOR_RED) | A_BOLD,
COLOR_PAIR(COLOR_CYAN) | A_BOLD,
COLOR_PAIR(COLOR_WHITE) | A_BOLD,
COLOR_PAIR(COLOR_MAGENTA) | A_BOLD,
COLOR_PAIR(COLOR_BLUE) | A_BOLD,
COLOR_PAIR(COLOR_YELLOW) | A_BOLD,
};
#endif /* CURSES */
int attrok(char attr)
/* is a given attribute supported? */
{
#ifdef CURSES
return(strchr(attrnames, attr) != (char *)NULL);
#endif /* CURSES */
}
void sattrset(char attr)
/* set the screen attribute indicated by a given character */
{
#ifdef CURSES
attrset(colorpairs[strchr(attrnames, attr) - attrnames]);
#endif /* CURSES */
}
char *username(void)
/* get name of user */
{
return(getlogin());
}
/* screen.c ends here */